package org.example;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import org.example.entity.ParseDocument;
import org.example.utils.COMMON;
import org.example.utils.doc.DocUtils;

import java.util.ArrayList;
import java.util.List;

public class DocInputDemo {

//    public static List<Message> messages= new ArrayList<>();
//
//    public static Integer token = 0;
//
//    public static GenerationParam createGenerationParam() {
//        return GenerationParam.builder()
//                .apiKey(COMMON.API_KEY)
//                .model(COMMON.MODEL)
//                .messages(messages)
//                .build();
//    }

    public static GenerationResult callGenerationWithMessages(GenerationParam param) throws ApiException, NoApiKeyException, InputRequiredException {
        Generation gen = new Generation();
        return gen.call(param);
    }

    public static void main(String[] args) {

        String FilePath = "G:\\destop\\learn.txt";
        ParseDocument parseDocument = DocUtils.recognize(FilePath);

        System.out.println(parseDocument.toString());

        Message userMsg = Message.builder()
        .role(Role.USER.getValue())
        .content("用户提交了一个文件\n"+parseDocument.toString())
        .build();

        Message systemMsg = Message.builder()
                .role(Role.SYSTEM.getValue())
                .content("you are a helpful assistant")
                .build();
        StreamingConversation.messages.add(systemMsg);
        StreamingConversation.messages.add(userMsg);
        StreamingConversation.main(null);

    }
}
